<?php
include('../common/_const.php');
include('../common/common.php');
include('../common/checksession.php');
checksession("../index.php");
include('../../inc/conn.php');
date_default_timezone_set('Asia/Chongqing');//设置时区



$rootname		=$_POST['idname'];
$pwd			=$_POST['pwd'];
$email			=$_POST['email'];
$loginip=GetIP();//获取管理员登陆ip
$logintime=date('Y-m-d h:i a');
$gurl			=$_POST['gurl'];

if(!islogintxt($rootname)){
	ShowMsg("账号有非法字符！",$gurl);
	exit;
}
if(strlen($pwd)<6){
	ShowMsg("密码不能小于6位数",$gurl);
	exit;
}else{
	$pwd=md5(PREPWD.$pwd);
}

$db=db_connect();
$sql=select_sql("`rootname`","`".PRETABLE."adminuser`","`rootname`='".$rootname."'");
$rs=$db->query($sql);
if($rs->num_rows>0){
	ShowMsg("该账号已注册，操作失败！",$gurl);
	exit;
}

$sql=insert_sql("`".PRETABLE."adminuser`","`rootname`,`rootpws`,`email`,`logintims`,`lasttime`,`loginip`","'".$rootname."','".$pwd."','".$email."','0','".$logintime."','".$loginip."'");


if($db->query($sql)){
	ShowMsg_h("添加成功！","../moduls/member.php");
}else{
	ShowMsg("操作失败！",$gurl);
	exit;
}
$db->close();

?>